<?php
namespace app\jiyun\controller;

use app\common\model\jiyun\OrderPackingModel;
use app\jiyun\service\base\CommonService;
use think\admin\helper\QueryHelper;

class OrderPacking extends BaseController
{
    /**
     * 拣货单（入库列表）
     *
     * @auth true
     * @menu true
     * @return void
     */
    public function index ()
    {
        OrderPackingModel::mQuery()->layTable(function () {
            $this->title = '渠道列表';

            // 仓库
            $this->warehouse_arr = CommonService::instance()->getWarehouse($this->account_id);
            // 订单公司
            $this->company_arr   = CommonService::instance()->getShopOrderAccount($this->account_id);
            // 三方平台
            $this->platform_arr  = CommonService::instance()->getSystemPlatform();

            $this->status_arr    = OrderPackingModel::getStatusArr();

        }, function (QueryHelper $query) {

            //$query->with(['country','express','account']);
            $query->order('id', 'desc');
            // 数据列表搜索过滤
            $query->equal('account_id,warehouse_id,shop_account_id,platform_id,status')->like('order_no,goods_name,location_code')->dateBetween('create_at');
        });
    }


    protected function _index_page_filter (&$data)
    {
        $common_service   = CommonService::instance();
        // 获得仓库
        $warehouse_arr    = $common_service->getWarehouse($this->account_id);
        // 获得平台
        $system_platform  = $common_service->getSystemPlatform();
        // 获得公司名字
        $account          = $common_service->getAccount();

        foreach ($data as &$item) {
            $item['warehouse_name'] = $warehouse_arr[$item['warehouse_id']] ?? '';
            $item['platform_name']  = $system_platform[$item['platform_id']]  ?? '';
            $item['account_name']   = $account[$item['account_id']]  ?? '';
        }
    }


    /**
     * 编辑货位
     * @auth  true
     * @return void
     */
    public function edit ()
    {
        OrderPackingModel::mForm();
    }


}
?>